package com.example.birdfriends.service.impl;

import com.example.birdfriends.dao.MessageDao;
import com.example.birdfriends.pojo.message.Message;
import com.example.birdfriends.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;

    @Override
    public List<Message> findMessagesBySidAndRid(Long senderId, Long receiverId) {
        return messageDao.findMessagesBySidAndRid(senderId, receiverId);
    }

    public int addMessage(Message message){
        return messageDao.addMessage(message);
    }

    @Override
    public int updateMessageReadState(Message message) {
        // 更新信息的阅读状态
        return messageDao.updateMySendMsgReadState(message) + messageDao.updateMyReceiveMsgReadState(message);
    }

    @Override
    public int countUnReadMsgs(Long curLoginUid, Long friendId) {
        return messageDao.countMySendUnRead(curLoginUid, friendId) + messageDao.countMyReceiveUnRead(friendId, curLoginUid);
    }
}
